package com.example.viewpagertest;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainActivity extends Activity {

	private ViewPager viewPager;
	//private PagerTitleStrip pagerTitleStrip;
	private List<View> viewList;
	private List<String> titleList;
	@SuppressLint("InflateParams")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		viewPager = (ViewPager)this.findViewById(R.id.view_pager);
		//pagerTitleStrip = (PagerTitleStrip)findViewById(R.id.view_pager_title);
		View view1 = LayoutInflater.from(this).inflate(R.layout.title1, null);
		View view2 = LayoutInflater.from(this).inflate(R.layout.title1, null);
		View view3 = LayoutInflater.from(this).inflate(R.layout.title1, null);
		TextView text = (TextView)view1.findViewById(R.id.text);
		text.setText("123654");
		TextView text1 = (TextView)view1.findViewById(R.id.text);
		text1.setText("36987");
		TextView text2 = (TextView)view1.findViewById(R.id.text);
		text2.setText("12sadasd");
		viewList = new ArrayList<View>();
		viewList.add(view1);
		viewList.add(view2);
		viewList.add(view3);
		titleList = new ArrayList<String>();
		titleList.add("title1");
		titleList.add("title2");
		titleList.add("title3");
		viewPager.setAdapter(new MyAdapter());
	}

	class MyAdapter extends PagerAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return viewList.size();
		}

//		@Override
//		public float getPageWidth(int position) {
//			// TODO Auto-generated method stub
//			return titleList.size();
//		}
		@Override
		public CharSequence getPageTitle(int position) {
			// TODO Auto-generated method stub
			return titleList.get(position);
		}
		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub
			//super.destroyItem(container, position, object);
			((ViewPager)container).removeView(viewList.get(position));
		}
		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			// TODO Auto-generated method stub
			((ViewPager)container).addView(viewList.get(position));
			return viewList.get(position);			
		}
		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return arg0==arg1;
		}
		
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
